/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.iec.edp.caf.caching;

import io.iec.edp.caf.caching.aspect.LayeringAspect;
import io.iec.edp.caf.caching.properties.JedisPoolConfigProperties;
import io.iec.edp.caf.caching.properties.RedisCacheProperties;
import io.iec.edp.caf.caching.api.CacheManager;
import io.iec.edp.caf.caching.manager.LayeringCacheManager;
import io.iec.edp.caf.caching.properties.LayeringCacheProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

/**
 * 多级缓存自动配置类
 */
@Configuration(proxyBeanMethods = false)
@ComponentScan({"io.iec.edp.caf.caching"})
@EnableAspectJAutoProxy
@EnableConfigurationProperties({JedisPoolConfigProperties.class, LayeringCacheProperties.class, RedisCacheProperties.class})
public class LayeringCacheAutoConfig {

    @Bean
    public CacheManager cacheManager(RedisCacheProperties properties, JedisPoolConfigProperties jedisProperties, LayeringCacheProperties status) {
        LayeringCacheManager manager = new LayeringCacheManager(properties, jedisProperties);
        // 默认开启统计功能
        manager.setStats(status.isStats());
        return manager;
    }

    @Bean
    public LayeringAspect layeringAspect() {
        return new LayeringAspect();
    }

}
